cmake_minimum_required(VERSION 3.17)

get_filename_component(ProjectId ${CMAKE_CURRENT_SOURCE_DIR} NAME)
string(REPLACE " " "_" ProjectId ${ProjectId})
project(${ProjectId} C)

set(CMAKE_C_STANDARD 11)

#file(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/*.c")
#foreach(file ${files})
#    get_filename_component(name ${file} NAME)
#    add_executable(${name} ${file})
#endforeach()

# 获取当前目录下所有的子目录
file(GLOB SUBDIRS LIST_DIRECTORIES true ${CMAKE_CURRENT_SOURCE_DIR}/*)

# 循环遍历子目录并添加
foreach(SUBDIR ${SUBDIRS})
    if(IS_DIRECTORY ${SUBDIR})
        get_filename_component(DIR_NAME ${SUBDIR} NAME)

        # 排除特定的目录
        if(DIR_NAME STREQUAL ".idea" OR DIR_NAME STREQUAL "cmake-build-debug")
            continue()
        endif()

        # 检查是否包含 CMakeLists.txt 文件
        file(GLOB CMAKE_FILES ${SUBDIR}/CMakeLists.txt)
        if(CMAKE_FILES)
            add_subdirectory(${DIR_NAME})
        endif()
    endif()
endforeach()

#add_subdirectory(Chapter2)
#add_subdirectory(Chapter3)
#add_subdirectory(Chapter4)